package com.shudes.game;

import java.util.*;

public class CardCollection implements Iterable {

	protected ArrayList<Card> cards;	
	
	public CardCollection(int size) {
		cards = new ArrayList<Card>(size);
	}
		
	public CardCollection(Collection<Card> cards) { 
		this.cards = new ArrayList<Card>(cards.size()); 
		this.cards.addAll(cards);
	}
	
	public CardCollection(CardCollection cc) { 
		this.cards = new ArrayList<Card>(cc.count()); 
		this.add(cc); 
	}
	
	public Integer size() { 
		return cards.size();
	}
	
	protected  void add(Card c) { 
		cards.add(c); 
	}
	
	protected void add(CardCollection h) { 
		cards.addAll(h.getCards());
	}
	
	protected Card get(int index) { 
		return (index<0 || index >= cards.size()) ? null : (Card) cards.get(index); 
	}
	
	protected int count() { 
		return cards.size();
	}
	
	public ArrayList<Card> getCards() { 
		return new ArrayList<Card>(cards); 
	}

	@Override
	public boolean equals(Object obj) {
		if(obj==null || !(obj instanceof CardCollection))
			return false; 
		
		return this.hashCode()==obj.hashCode();
	}

	@Override
	public int hashCode() {
		return cards.toString().hashCode();
	}

	@Override
	public String toString() {
		return cards.toString();
	}
			
	public Iterator<Card> iterator() {		
		return this.cards.iterator();
	}

	protected ArrayList<Card> slice(Integer... index) {
		ArrayList<Card> result = new ArrayList<Card>();
		for(Integer i : index) { 
			if(i !=null && i >= 0 && i < cards.size()) {
				result.add(get(i));
			}
		}
		return result; 		
	}
	
	

}
